<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class UserAddress extends Model
{
    protected $fillable = [
        'customer_id',
        'province_id',
        'city_id',
        'district_id',
        'address',
        'is_default',
        'contact_name',
        'contact_phone',
        'zip',
    ];

    protected $appends = [
        'province',
        'city',
        'district',
    ];

    public function getAllAddressAttribute()
    {
        return getAllAddress($this->toArray());
    }

    public function getProvinceAttribute()
    {
        return ChinaArea::getNameByCode($this->province_id);
    }

    public function getCityAttribute()
    {
        return ChinaArea::getNameByCode($this->city_id);
    }

    public function getDistrictAttribute()
    {
        return ChinaArea::getNameByCode($this->district_id);
    }
}
